<template lang="pug">
.resetList
  el-dialog(title="重置用户密码" :visible="value" width="500px")
    el-form(:model="form")
      el-form-item(label="密码" label-width="100px")
        el-input(v-model="form.password" type="password" autocomplete="off" show-password)
      el-form-item(label-width="100px")
        el-button(size="mini" @click="onRand") 随机生成密码
      el-form-item(label-width="100px")
        el-button(type="primary" @click="onRend") 确认
        el-button 取消
</template>
<script>
export default {
  props:{
    value:{
      type:Boolean,
      default:false
    },
    roles:{
      type:Object,
      default:() =>({})
    }
  },
  data() {
    return {
      form: {
        password:''
      }
    }
  },
  methods: {
    // 随机密码
    onRand() {
      var num='';
      for(var i=0;i<6;i++){
        num += Math.floor(Math.random()*10)
      }
      this.form.password = num

    },
    onRend() {
      this.axios.post('/user/password',{
        id:this.roles.id,
        password:this.form.password
      }).then(({data}) => {
        if(!data.errcode) {
          this.$message({
            message: '重置成功',
            type: 'success'
          });
          this.$emit('input',false)
        }
      })
    }
  },
}
</script>
<style lang="sass">

</style>
